class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def bst_search(root, target):
    """
    二叉搜索树查找：利用BST左小右大的性质递归查找
    root：二叉搜索树根节点
    target：待查找元素
    """
    if not root or root.val == target:
        return root
    if root.val < target:
        return bst_search(root.right, target)
    else:
        return bst_search(root.left, target)

# 测试
# 构建BST：4→2→6→1→3→5→7
root = TreeNode(4,
                left=TreeNode(2, left=TreeNode(1), right=TreeNode(3)),
                right=TreeNode(6, left=TreeNode(5), right=TreeNode(7)))
result = bst_search(root, 5)
print(result.val if result else -1)  # 输出：5
print(bst_search(root, 8))           # 输出：None